<template>
	<view class="bind-wx" @click="wechatLogin">
		<view class="wx-icon"><u-icon name="weixin-fill" size="50"></u-icon></view>
		<view class="tips">点击绑定微信</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		methods: {
			wechatLogin(){
				let _this = this
				let weixinService = null;
				plus.oauth.getServices((services) => {
					services.forEach(item => {
						if(item.id==='weixin'){
							weixinService = item
						}
					})
					if(!weixinService) {
						uni.showToast({
							icon: 'none',
							title: '没有微信登录授权服务'
						})
						return;
					}
					weixinService.authorize((e) => {
						_this.$u.api.NewAppBinding({
							code: e.code,
							phone: JSON.parse(uni.getStorageSync('userInfo')).phone,
							type: 2,
						}).then(res => {
							uni.setStorageSync('userInfo',JSON.stringify(res.datas))
							uni.showToast({
								icon: 'none',
								title: '绑定成功',
								duration: 1500
							})
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/index/index'
								})
							},1500)
						})
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.bind-wx{
		text-align: center;
		margin-top: 50rpx;
		.wx-icon{
			width: 90rpx;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 50%;
			border: solid 2rpx #7e7e7e;
			margin: 0 auto;
		}
		.tips{
			margin-top: 20rpx;
			font-size: 28rpx;
		}
	}
</style>
